const express = require('express');
const  router = express.Router();
const path = require('path');
const PositionService = require('../service/position-service')
//引入 multer
const multer = require('multer');

//文件上传
const storage = multer.diskStorage({
    //指定目标文件夹
    destination: function (req, file, cb) {

      //引入path模块,使用path.join的绝对路径
      cb(null, path.join(__dirname,'../public/images/upload/'))
    },

    //每个函数都传递了请求对象 (req) 和一些关于这个文件的信息 (file)，有助于你的决定,fieldname为form表单的name
    filename: function (req, file, cb) {
      cb(null, file.fieldname + '-' + Date.now()+file.originalname.slice(file.originalname.lastIndexOf('.')))
    }
  })
  
  var upload = multer({ storage: storage })

  //添加职位,logo为form的name值
  router.post('/add',upload.single('logo'),PositionService.add);
  //查询分页
  router.get('/page',PositionService.findPage);

/**登录 :post请求'/api/user/login' */
//router.post('/add',PositionService.add)



module.exports = router;
